package amani.wechat.platform.services.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import amani.wechat.platform.controller.model.ActivtyNews;
import amani.wechat.platform.services.IActivityService;
import amani.wechat.platform.services.IBookService;
import amani.wechat.platform.services.ICommonService;

@Service("ActivityService")
public class ActivityService implements IActivityService {
	@Resource(name="CommonService")
	ICommonService commonService ;
	
	
	@Override
	public List<ActivtyNews> getNewsList() { 
		 List<ActivtyNews>  result=new ArrayList<ActivtyNews>();
		 
		 List<Map<String, Object>>  list= commonService.getNewsListByCid("2");
		 if(list!=null && !list.isEmpty()){
			 for (int i = 0; i < list.size(); i++) {
				 ActivtyNews temp=new ActivtyNews();
				 temp.setId((Integer)list.get(i).get("id"));
				 temp.setUid((Integer)list.get(i).get("uid"));
				 temp.setCid((Integer)list.get(i).get("cid"));
				 temp.setType((Boolean)list.get(i).get("type"));
				 temp.setTitle((String)list.get(i).get("title"));
				 temp.setSubtitle((String)list.get(i).get("subtitle"));
				 temp.setPath((String)list.get(i).get("path"));
				 temp.setDescr((String)list.get(i).get("descr"));
				 temp.setContent((String)list.get(i).get("content"));
				 temp.setSourceFrom((String)list.get(i).get("sourceFrom"));
				 temp.setAuthor((String)list.get(i).get("author"));
				 temp.setLink((String)list.get(i).get("link"));
				 temp.setVideopath((String)list.get(i).get("videopath"));
				 temp.setHits((Integer)list.get(i).get("hits"));
				 temp.setTags((String)list.get(i).get("tags"));
				 temp.setIsrec((Boolean)list.get(i).get("isrec"));
				 temp.setHot((Boolean)list.get(i).get("hot"));
				 temp.setNew_((Boolean)list.get(i).get("new_"));
				 temp.setPraise((Integer)list.get(i).get("praise"));
				 temp.setFav((Integer)list.get(i).get("fav"));
				 temp.setIsopen((Boolean)list.get(i).get("isopen"));
				 temp.setUptime((Integer)list.get(i).get("uptime"));
				 temp.setCreatetime((Integer)list.get(i).get("createtime"));
				 temp.setSort((Integer)list.get(i).get("sort"));
				 if(temp.getLink()==null||temp.getLink()==""){
					 temp.setClink("Activity/Details"+"?newId="+temp.getId()); 
				 }else{
					 temp.setClink(temp.getLink()); 
				 }
				 result.add(temp);
			}
		 }
		
		return result;
	}

	@Override
	public ActivtyNews getNewsById(String id) {
		ActivtyNews result=new ActivtyNews();
		Map<String, Object> itemMap=	commonService.getNewsById(id);
		// TODO Auto-generated method stub
		 result.setId((Integer)itemMap.get("id"));
		 result.setUid((Integer)itemMap.get("uid"));
		 result.setCid((Integer)itemMap.get("cid"));
		 result.setType((Boolean)itemMap.get("type"));
		 result.setTitle((String)itemMap.get("title"));
		 result.setSubtitle((String)itemMap.get("subtitle"));
		 result.setPath((String)itemMap.get("path"));
		 result.setDescr((String)itemMap.get("descr"));
		 result.setContent((String)itemMap.get("content"));
		 result.setSourceFrom((String)itemMap.get("sourceFrom"));
		 result.setAuthor((String)itemMap.get("author"));
		 result.setLink((String)itemMap.get("link"));
		 result.setVideopath((String)itemMap.get("videopath"));
		 result.setHits((Integer)itemMap.get("hits"));
		 result.setTags((String)itemMap.get("tags"));
		 result.setIsrec((Boolean)itemMap.get("isrec"));
		 result.setHot((Boolean)itemMap.get("hot"));
		 result.setNew_((Boolean)itemMap.get("new_"));
		 result.setPraise((Integer)itemMap.get("praise"));
		 result.setFav((Integer)itemMap.get("fav"));
		 result.setIsopen((Boolean)itemMap.get("isopen"));
		 result.setUptime((Integer)itemMap.get("uptime"));
		 result.setCreatetime((Integer)itemMap.get("createtime"));
		 result.setSort((Integer)itemMap.get("sort"));
		 if(result.getLink()==null||result.getLink()==""){
			 result.setClink("Activity/Details"+"?newId="+result.getId()); 
		 }else{
			 result.setClink(result.getLink()); 
		 }
		return result;
	}

}
